package 山脉数组的峰顶索引;

class Solution {
    //暴力求解
    public int peakIndexInMountainArray1(int[] arr) {
        int ret = 0;
        for(int i = 1; i < arr.length - 1; i++){
            if(arr[i] > arr[i - 1] && arr[i] > arr[i + 1]){
                ret = i;
                break;
            }
        }
        return ret;
    }

    //二分查找算法求解
    public int peakIndexInMountainArray(int[] arr) {
        int left = 0;
        int right = arr.length - 1;
        while(left < right){
            int mid = left + (right - left + 1) / 2;
            if(arr[mid] > arr[mid - 1]){
                left = mid;
            }else {
                right = mid - 1;
            }
        }
        return right;
    }
}